package com.ruoyi.health.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.health.domain.Notice;
import com.ruoyi.health.service.INoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 养老资讯Controller
 * 
 * @author dalian
 * @date 2023-08-05
 */
@Api("养老资讯-资讯管理")
@RestController
@RequestMapping("/health/healthNotice")
public class NoticeController extends BaseController
{
    @Autowired
    private INoticeService noticeService;

    /**
     * 查询养老资讯列表【8.7已完成】
     * @param  cate1Id 一级分类id（二级分类id 在 notice中）
     */
    // @PreAuthorize("@ss.hasPermi('health:healthNotice:list')")
    @ApiOperation("查询养老资讯列表")
    @GetMapping("/list")
    public TableDataInfo list(Notice notice,Long cate1Id)
    {
        startPage();
        //根据分类、标题，条件查询
        List<Notice> list = noticeService.selectNoticeList(notice,cate1Id);
        return getDataTable(list);
    }

    /**
     * 导出养老资讯列表
     */
    @PreAuthorize("@ss.hasPermi('health:healthNotice:export')")
    @Log(title = "养老资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notice notice)
    {
        List<Notice> list = noticeService.selectNoticeList(notice,null);
        ExcelUtil<Notice> util = new ExcelUtil<Notice>(Notice.class);
        util.exportExcel(response, list, "养老资讯数据");
    }

    /**
     * 获取养老资讯信息
     */
    // @PreAuthorize("@ss.hasPermi('health:healthNotice:query')")
    @ApiOperation("获取养老资讯信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(noticeService.selectNoticeById(id));
    }

    /**
     * 新增养老资讯
     */
    @ApiOperation("新增养老资讯")
    @PreAuthorize("@ss.hasPermi('health:healthNotice:add')")
    @Log(title = "养老资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notice notice)
    {
        notice.setCreateBy(getUsername());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改养老资讯
     */
    @ApiOperation("修改养老资讯")
    @PreAuthorize("@ss.hasPermi('health:healthNotice:edit')")
    @Log(title = "养老资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notice notice)
    {
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除养老资讯
     */
    @ApiOperation("删除养老资讯")
    @PreAuthorize("@ss.hasPermi('health:healthNotice:remove')")
    @Log(title = "养老资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(noticeService.deleteNoticeByIds(ids));
    }
}
